<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page isELIgnored="false" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<script type="text/javascript" src="<%=request.getContextPath()%>/resources/js/locale/easyui-lang-zh_CN.js"></script>
		<script type="text/javascript">
			jQuery(function(){
				jQuery("#wfpGrid").datagrid({
					url: '<%=request.getContextPath() %>/user/getWfpUserList?roleId=${role.id}',
					width: 400,
					height: 230,
					pagination:true,
					//view:'scrollview',
					columns:[[
						{field:'userid',checkbox:true},
						{field:'username',title:'用户名',width:'130'},
						{field:'nickname',title:'昵称',width:'160'}
					]]
				});
				
				//设置分页控件  
			    var p = jQuery('#wfpGrid').datagrid('getPager');  
			    jQuery(p).pagination({  
			       	showRefresh:false,
			       	showPageList:false,
			       	buttons:[{
			            iconCls:'icon-search',
			            handler:function(){
			               
			            }
			        }],
			        displayMsg: ''
			    });  
			    
			    
			    jQuery("#yfpGrid").datagrid({
					url: '<%=request.getContextPath() %>/user/getYfpUserList?roleId=${role.id}',
					width: 400,
					height: 230,
					pagination:true,
					//view:'scrollview',
					columns:[[
						{field:'userid',checkbox:true},
						{field:'username',title:'用户名',width:'130'},
						{field:'nickname',title:'昵称',width:'160'}
					]]
				});
			    
			    //设置分页控件  
			    var pager = jQuery('#yfpGrid').datagrid('getPager');  
			    jQuery(pager).pagination({  
			       	showRefresh:false,
			       	showPageList:false,
			       	buttons:[{
			            iconCls:'icon-search',
			            handler:function(){
			               
			            }
			        }],
			        displayMsg: ''
			    });  
			})
			
			function toRight(){
				
				var userid = [];
				var rows = jQuery("#wfpGrid").datagrid("getSelections");
				for (var i = 0; i < rows.length; i++) {  
                 	userid.push(rows[i]["userid"]);
				}
				
				if (userid.length == 0){
					return false;
				}
				
				jQuery.post("<%=request.getContextPath() %>/role/saveRoleUsers",{ids:userid.join(","),roleId:jQuery("#roleId").val()},function(data){
					if (data){
						jQuery("#wfpGrid").datagrid('reload');
						jQuery("#yfpGrid").datagrid('reload');
					}
				},"json");
				
			}
			
			function toLeft(){
				
				var userid = [];
				var rows = jQuery("#yfpGrid").datagrid("getSelections");
				for (var i = 0; i < rows.length; i++) {  
                 	userid.push(rows[i]["userid"]);
				}
				
				if (userid.length == 0){
					return false;
				}
				
				jQuery.post("<%=request.getContextPath() %>/role/delRoleUsers",{ids:userid.join(","),roleId:jQuery("#roleId").val()},function(data){
					if (data){
						jQuery("#wfpGrid").datagrid('reload');
						jQuery("#yfpGrid").datagrid('reload');
					}
				},"json");
				
			}
			
		</script>
	</head>
	
	
	
	
	<div class="easyui-layout" data-options="fit:true,border:false">
		<div data-options="region:'center',border:false" title="" style="overflow: hidden;">
			<form id="form" method="post" >
				<input type="hidden" name="id" value="${role.id}" id="roleId">
				<table class="formtab">
					<tr>
						<th width="15%">角色名称</th>
						<td width="30%">${role.name}</td>
						<th width="15%" colspan="2">上级角色</th>
						<td >${role.role.name}</td>
					</tr>
					<tr>
						<th>描&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;述</th>
						<td colspan="4">
							${role.description}
						</td>
					</tr>
					<tr>
						<td colspan="2" align="center">
							<table id="wfpGrid"></table>
						</td>
						<td width="12%" align="center">
							<a href="#" class="easyui-linkbutton" onclick="toRight();">右移</a><br/><br/>
							<a href="#" class="easyui-linkbutton" onclick="toLeft();">左移</a>
						</td>
						<td colspan="2" align="center">
							<table id="yfpGrid"></table>
						</td>
					</tr>
				</table>
			</form>
		</div>
	</div>
</html>
